package rauguelu.programaEventos;

import java.util.List;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Typeface;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class infoFestival extends MapActivity  {

	private MapView mapa = null;
	private MapController controlMapa = null;
	private LocationManager locManager;

	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.info_festival);

			TextView comoLLegar = (TextView)findViewById(R.id.comoLlegar);			
			TextView verWeb = (TextView)findViewById(R.id.verWeb);	
			ImageView facebook_sentidos = (ImageView)findViewById(R.id.facebook_sentidos);
			ImageView twitter_sentidos = (ImageView)findViewById(R.id.twitter_sentidos);
			TextView dsTitulo = (TextView)findViewById(R.id.dsTitulo);
			TextView dsTitulo1 = (TextView)findViewById(R.id.dsTitulo1);
			TextView dsTitulo2 = (TextView)findViewById(R.id.dsTitulo2);
			TextView dsCabecera = (TextView)findViewById(R.id.dsCabecera);
			
			Typeface font = Typeface.createFromAsset(getAssets(), "VSVBPSB.TTF");
			comoLLegar.setTypeface(font);
			verWeb.setTypeface(font);
			dsCabecera.setTypeface(font);
			
			Typeface font2 = Typeface.createFromAsset(getAssets(), "VSVAB.TTF");
			dsTitulo.setTypeface(font2);
			dsTitulo1.setTypeface(font2);
			dsTitulo2.setTypeface(font2);
			
		    //Obtenemos una referencia a los controles
	        mapa = (MapView)findViewById(R.id.mapa);
	        mapa.setSatellite(false);	        
	        
			Double latitud = 39.202564*1E6;
			Double longitud = -2.157223*1E6;
	 
       
	        mapa.setBuiltInZoomControls(true);
	        
			//A�adimos la capa de marcas
			List<Overlay> capas = mapa.getOverlays();
			OverlayMapa om = new OverlayMapa();
			capas.add(om);
			mapa.postInvalidate();
	        
	        //Controlador del mapa
	        controlMapa = mapa.getController();
	        
	        GeoPoint loc =
		            new GeoPoint(latitud.intValue(), longitud.intValue());
		 
		        controlMapa.setCenter(loc);
		        controlMapa.setZoom(15);
	        
			verWeb.setOnClickListener(new View.OnClickListener(){
				    public void onClick(View v){
				        Intent intent = new Intent();
				        intent.setAction(Intent.ACTION_VIEW);
				        intent.addCategory(Intent.CATEGORY_BROWSABLE);
				        intent.setData(Uri.parse("http://www.laroda.es/sentidos/"));
				        startActivity(intent);
				    }
				});
			 
	        comoLLegar.setOnClickListener(new View.OnClickListener() {
					public void onClick(View view) {
						//startActivity(new Intent(view.getContext(), ProgramaEventos.class));
						Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
						Uri.parse(obtenerDireccion()));
						startActivity(intent);
					}
			 	});
	        
	        facebook_sentidos.setOnClickListener(new View.OnClickListener(){
			    public void onClick(View v){
			        Intent intent = new Intent();
			        intent.setAction(Intent.ACTION_VIEW);
			        intent.addCategory(Intent.CATEGORY_BROWSABLE);
			        intent.setData(Uri.parse("http://www.facebook.com/festivaldelossentidos"));
			        startActivity(intent);
			    }
			});
			
			
	        	twitter_sentidos.setOnClickListener(new View.OnClickListener(){
				    public void onClick(View v){
				        Intent intent = new Intent();
				        intent.setAction(Intent.ACTION_VIEW);
				        intent.addCategory(Intent.CATEGORY_BROWSABLE);
				        intent.setData(Uri.parse("https://twitter.com/#!/fdelossentidos"));
				        startActivity(intent);
				    }
				});
		        
	        }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
    private String obtenerDireccion()
    {

    	//Obtenemos una referencia al LocationManager
    	locManager = 
    		(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    	
    	//Obtenemos la �ltima posici�n conocida
    	Location loc = 
    		locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    	
    	  
    	return "http://maps.google.com/maps?saddr="+loc.getLatitude()+","+loc.getLongitude()+"&daddr=39.20311, -2.15788";
    	
    }
     
}